package com.hzhc.controller.baseinfo;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.entity.CntrMain;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.CntrMainService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.CntrMainVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 箱主信息 前端控制器
 * </p>
 *
 * @author 功不唐捐
 * @since 2024-05-23
 */
@RestController
@RequestMapping("/cntrMain")
@RequiredArgsConstructor
public class CntrMainController extends BaseController {

    private final CntrMainService mainService;

    /**
     * 箱主维护 列表list
     * @param request
     * @param vo
     * @return
     */
    @PostMapping("/getCntrMainList")
    public ResultUtil<List<CntrMainVo>> getCntrMainList(HttpServletRequest request, @RequestBody CntrMainVo vo){
        Page<CntrMainVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<CntrMainVo> list = mainService.getCntrMainList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 箱主维护 add
     * @param request
     * @param main
     * @return
     */
    @PostMapping("/addCntrMain")
    @SysTemLog(operModul = "箱管理-箱主维护",operType = "ADD",operDesc = "箱主维护添加",modular="PC")
    public ResultUtil<T> addCntrMain(HttpServletRequest request,@RequestBody CntrMain main){
        Long userID = TokenUtil.getUserID(request);
        main.setUserId(userID);
        main.setCreateTime(LocalDateTime.now());
        return mainService.addCntrMain(main);
    }

    @PostMapping("/checkMainName")
    public ResultUtil<T> checkMainName(HttpServletRequest request,@RequestBody CntrMain main){
        Boolean b = mainService.checkMainName(main);
        if (b){
            return ResultUtil.ok();
        }
        return ResultUtil.build(ResultUtilCodeEnum.CNTR_MASTER_EXIST);
    }

    /**
     * 箱主维护 update
     * @param request
     * @param main
     * @return
     */
    @PostMapping("/updateCntrMian")
    @SysTemLog(operModul = "箱管理-箱主维护",operType = "UPDATE",operDesc = "箱主维护修改",modular="PC")
    public ResultUtil<T> updateCntrMian(HttpServletRequest request,@RequestBody CntrMain main){
        Long userID = TokenUtil.getUserID(request);
        main.setUpdateUserId(userID);
        main.setUpdateTime(LocalDateTime.now());
        return mainService.updateCntrMian(main);
    }

    /**
     * 箱主维护 del
     * @param request
     * @param id
     * @return
     */
    @PostMapping("/delCntrMain/{id}")
    @SysTemLog(operModul = "箱管理-箱主维护",operType = "DELETE",operDesc = "箱主维护删除",modular="PC")
    public ResultUtil<T> delCntrMain(HttpServletRequest request, @PathVariable Long id){
        return mainService.delCntrMain(id);
    }



}
